package com.atguigu.springbootdemo.service;

import com.atguigu.springbootdemo.beans.Employee;
import com.atguigu.springbootdemo.beans.MyData;
import com.atguigu.springbootdemo.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Smexy on 2023/3/28
 *
 *  @Service 有两个作用:
 *          ①告诉同事，当前这个类是一个业务模型。
 *          ②容器扫描到后，会自动为顶了这个注解的类，创建一个单例对象。
 */
@Service
public class EmployeeServiceImpl2 implements EmployeeService
{
    //声明Dao
    @Autowired
    private EmployeeMapper mapper;
    @Override
    public Employee getEmpById(Integer id) {

        System.out.println("规定了操作前做....事情");

        Employee emp = mapper.getEmpById(id);

        System.out.println("规定了操作后做....事情");

        return emp;
    }

    @Override
    public void insertEmployee(Employee e) {

        System.out.println("规定了操作前做....事情");

        mapper.insertEmployee(e);

        System.out.println("规定了操作后做....事情");
    }

    @Override
    public void updateEmployee(Employee e) {

        System.out.println("规定了操作前做....事情");

        mapper.updateEmployee(e);

        System.out.println("规定了操作后做....事情");
    }

    @Override
    public void deleteEmpById(Integer id) {

        System.out.println("规定了操作前做....事情");

        mapper.deleteEmpById(id);

        System.out.println("规定了操作后做....事情");
    }

    @Override
    public List<Employee> getAll() {

        System.out.println("规定了操作前做....事情");

        List<Employee> emps = mapper.getAll();

        System.out.println("规定了操作后做....事情");

        return emps;
    }

    @Override
    public List<MyData> getAds() {

        System.out.println("规定了操作前做....事情");

        List<MyData> data = mapper.getAds();

        System.out.println("规定了操作后做....事情");

        return data;
    }
}
